import { BasicEntity } from "src/common/entity/basic.entity";
import { FileInfo } from "src/core/system/minio/entities/file_info.entity";
import { User } from "src/core/system/user/entities/user.entity";
import { Column, Entity, JoinTable, ManyToMany, OneToMany, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import { Artist } from "../../artist/entities/artist.entity";
import { Category } from "../../category/entities/category.entity";
import { Song } from "../../song/entities/song.entity";

//专辑实体
@Entity("album")
export class Album extends BasicEntity {
  @PrimaryGeneratedColumn()
  id: number

  //专辑唯一代码（P10004217236）
  @Column({
    type: 'varchar',
    // unique: true,
    comment: "专辑唯一代码（P10004217236）"
  })
  albumAssetCode: string;


  //发行日期
  @Column({
    name: "release_date",
    type: "date",
    comment: "发行日期"
  })
  releaseDate: Date;



  //专辑介绍
  @Column({
    name: "introduce",
    type: "varchar",
    comment: "专辑介绍"
  })
  introduce: string;


  // //封面图
  // @Column({
  //   type: "varchar",
  //   comment: "封面图"
  // })
  // pic: string;

  //2:免费 3:收费
  @Column({
    type: 'int',
    name: "pay_model",
    default: 2,
    comment: "2:免费 3:收费"
  })
  payModel: number;


  //专辑标题
  @Column({
    name: "title",
    type: "varchar",
    comment: "专辑标题"
  })
  title: string;



  //语言（中文）
  @Column({
    name: "lang",
    type: "varchar",
    comment: "语言（中文）"
  })
  lang: string;


  //本站推出时间
  @Column({
    name: "push_time",
    type: "date",
    comment: "本站推出时间"
  })
  pushTime: Date;

  //本站下架时间
  @Column({
    name: "down_time",
    type: "date",
    comment: "本站下架时间"
  })
  downTime: string;


  //专辑中歌曲列表
  @OneToMany(() => Song, song => song.album, {
    cascade: true
  })
  trackList: Song[];

  //所属的歌手列表
  @ManyToMany(() => Artist, (artist) => artist.albums, {
    cascade: true,
  })
  artistList: Artist[];


  //喜欢此专辑的人
  @ManyToMany(() => User, user => user.favorSongList, {
    cascade: true,
  })
  @JoinTable({
    name: "album_user_favor", //生成的中间表名
    joinColumn: {
      name: "album_id", //生成的列名
      referencedColumnName: "id" //需要关联的列
    },
    inverseJoinColumn: {
      name: "user_id", //需要被关联的生成的列名
      referencedColumnName: "id"//需要关联的列
    }
  })
  favoriteUsers: User[];

  //购买此专辑的人
  @ManyToMany(() => User, user => user.paidSongList, {
    cascade: true,
  })
  @JoinTable({
    name: "album_user_paid", //生成的中间表名
    joinColumn: {
      name: "album_id", //生成的列名
      referencedColumnName: "id" //需要关联的列
    },
    inverseJoinColumn: {
      name: "user_id", //需要被关联的生成的列名
      referencedColumnName: "id"//需要关联的列
    }
  })
  paidUsers: User[];

  //专辑分类（流行）
  //类别下面的子类别(摇滚-朋克)
  @ManyToMany(() => Category, cate => cate.albumList, {
    cascade: true,
  })
  @JoinTable({
    name: "album_cate", //生成的中间表名
    joinColumn: {
      name: "album_id", //生成的列名
      referencedColumnName: "id" //需要关联的列
    },
    inverseJoinColumn: {
      name: "cate_id", //需要被关联的生成的列名
      referencedColumnName: "id"//需要关联的列
    }
  })
  genre: Category[];

  //封面图
  @OneToOne(() => FileInfo, (file) => file.album, {
    cascade: ['remove'],
    // onDelete: 'CASCADE',
  })
  pic: FileInfo

}


